﻿using System;
using Microsoft.Xna.Framework.Graphics;
using OilRigSumoWrestlers.Actions;
using OilRigSumoWrestlers.Components;
using OilRigSumoWrestlers.Controllables;
using OilRigSumoWrestlers.Entities;
using RaptorEngine;
using RaptorEngine.Components;
using RaptorEngine.Components.CollidableComponent;
using RaptorEngine.Components.Drawable;
using Microsoft.Xna.Framework;

namespace OilRigSumoWrestlers.Scenes
{
    class MultiplayerLocalScene : Scene
    {

        public MultiplayerLocalScene(bool network) : base(network)
		{
			Camera = new Camera(new Vector3(20, 0, 20), new Vector3(20, 50, 50));


            CreateScene();
        }

        private void CreateScene()
        {
            /*Entity snoplao = new Entity();
            snoplao.Position = new Vector3(-1, 0, 10);
            snoplao.AddComponent(new DrawableModel(snoplao, GameEngine.Instance.Load<Model>("Models/snowplow"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
            snoplao.AddComponent(new TestControllable(snoplao));

            Entity franky = new Entity();
            franky.Position = new Vector3(50, 50, 0);
            franky.AddComponent(new DrawableSprite(franky, GameEngine.Instance.Load<Texture2D>("Images/franky2")));
            //franky.AddComponent(new TestControllable(franky));

            Entity ball = new Entity();
            ball.Position = new Vector3(0, 0, 0);
            ball.AddComponent(new DrawableModel(ball, GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));

            Entity e = new Entity();
            e.Scale = .03f;
            e.AddComponent(new DrawableAnimation(e, GameEngine.Instance.Load<Model>("Models/dude"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
			*/
			Entity ball = new Entity();
			ball.Position = new Vector3(10, 20, 10);
			ball.AddComponent(new DrawableModel(ball, GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
			ball.AddComponent(new Collidable(ball, new NormalBounce(1), GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), true, (int)CollisionType.Player));
			ball.AddComponent(new Movable(ball, GameConstant.PLAYER_MASS));
			ball.AddComponent(new TestControllable(ball));
			AddEntity(ball);

			Entity ball2 = new Entity();
			ball2.Position = new Vector3(20, 20, 20);
			ball2.AddComponent(new DrawableModel(ball2, GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
			ball2.AddComponent(new Collidable(ball2, new NormalBounce(1), GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), true, (int)CollisionType.Player));
			ball2.AddComponent(new Movable(ball2, GameConstant.PLAYER_MASS));
			ball2.AddComponent(new TestControllable2(ball2));
			AddEntity(ball2);

			Random r = new Random();
	        Entity cube;
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					if (i == 0 || i == 7 || j == 0 || j == 7)
					{
						if (r.Next(3) < 3)
						{
							cube = new Entity();
							cube.Scale = 3;
							cube.Position = new Vector3(i*2*cube.Scale, 2*cube.Scale, j*2*cube.Scale);
							cube.AddComponent(new DrawableModel(cube, GameEngine.Instance.Load<Model>("Models/Cube/cube"),
							                                    new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
							cube.AddComponent(new Collidable(cube, new BouncableCube(.75f), GameEngine.Instance.Load<Model>("Models/Cube/cube"), false,
							                                 (int) CollisionType.Ground));
							AddEntity(cube);
							continue;
						}
					}
					if (i == 4 && j == 5)
					{
						cube = new Entity();
						cube.Scale = 3;
						cube.Position = new Vector3(i * 2 * cube.Scale, 2 * cube.Scale, j * 2 * cube.Scale);
						cube.AddComponent(new DrawableModel(cube, GameEngine.Instance.Load<Model>("Models/Cube/cube"),
															new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
						cube.AddComponent(new Collidable(cube, new BouncableCube(.75f), GameEngine.Instance.Load<Model>("Models/Cube/cube"), false,
															(int)CollisionType.Ground));
						AddEntity(cube);
						continue;
					}
					cube = new Entity();
					cube.Scale = 3;
					cube.Position = new Vector3(i * 2 * cube.Scale, 2, j * 2 * cube.Scale);
					cube.AddComponent(new DrawableModel(cube, GameEngine.Instance.Load<Model>("Models/Cube/cube"),
						                                new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
					if (r.Next(2) < 1)
					{
						cube.AddComponent(new Collidable(cube, new Floor(.99f), GameEngine.Instance.Load<Model>("Models/Cube/cube"), false,
						                                 (int) CollisionType.Ground));
					}
					else
					{
						cube.AddComponent(new Collidable(cube, new Floor(1f), GameEngine.Instance.Load<Model>("Models/Cube/cube"), false,
														(int)CollisionType.Ground));
					}
					AddEntity(cube);
				}
			}

			

            //Entity stillBall = new Entity();
            //stillBall.Position = new Vector3(9, -.5f, -.5f);
            //stillBall.AddComponent(new DrawableModel(stillBall, GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), new BasicEffect(GameEngine.Instance.Render.GraphicsDevice)));
            //stillBall.AddComponent(new Collidable(stillBall, new NormalBounce(), GameEngine.Instance.Load<Model>("Models/Sphere/sphere_mapped"), true));
            //AddEntity(stillBall);

            

            //for (int i = 0; i < 10; i++)
            //{
            //    Entity AI = new FuzzyAI(new Vector3(i*5, 10f, 0f));
            //    ((AIComponent)AI.Components[ComponentType.Controllable]).AddEnemy(stillBall);
            //    AddEntity(AI);
            //}

            //AddEntity(e);
            //AddEntity(franky);
            //AddEntity(snoplao);


            //e = new Entity();
            //e.AddComponent(new DrawableText(e, GameEngine.Instance.Load<SpriteFont>("Fonts/testFont"), "Detta fungerar."));
            //AddEntity(e);

            //e = new Entity();
            //e.AddComponent(new DrawableSprite(e, GameEngine.Instance.Load<Texture2D>("Images/black"), Color.White, .7f));
            //e.Scale = GameEngine.Instance.Render.GraphicsDevice.Viewport.Width;
            //AddEntity(e);

            //e = new Entity();
            //e.Position = new Vector3(400, 100, 0);
            //e.AddComponent(new DrawableSprite(e, GameEngine.Instance.Load<Texture2D>("Images/Frankytauro")));
            //AddEntity(e);

            //e = new Entity();
            //e.Position = new Vector3(GameEngine.Instance.Render.GraphicsDevice.Viewport.Width / 2 + 20, GameEngine.Instance.Render.GraphicsDevice.Viewport.Height / 2 + 130, 0);
            //e.AddComponent(new DrawableText(e, GameEngine.Instance.Load<SpriteFont>("Fonts/testFont"), "KENTAURU MOODO!!!!"));
            //AddEntity(e);

        }     
    }
}
